

a <- 1.05
b <- -100
y0 <- 3000

n<- 20

y0 * a + b

y <- numeric(n)
cal_y <- numeric(n)

y[1] <- y0

cal_y[1] <- y0

for(i in 1:(n-1)){
  y[i+1] <- a * y[i] + b
}

h <- b / (1-a)
c <- y0 - h

h + c * a^0


for(i in 1:n){
  cal_y[i] <- h + c * a^(i-1)
}

plot(0:(n-1), y, type = "b", col = "blue", pch = 19,
     xlab = "t", ylab = "y_t",
     main = "Difference Equation y = 1.05 * y_{t-1} + 100")

lines(0:(n-1), cal_y, col = "red", lty = 2, pch = 19)

# abline(h = b / (1-a), col = "red", lty = 2)

